package com.feng.service;

import imageUtil.ImageLoader;

import java.io.File;
import java.io.IOException;

import com.feng.dao.UserDao;
import com.feng.entity.User;
import com.feng.util.StringUtil;

public class ServletUser {
	UserDao dao = new UserDao();
	public void create(String mail, String name, String pwd) {
		User user = new User();
		user.setId(StringUtil.getId());
		user.setEmail(mail);
		user.setUserName(name);
		user.setPassword(pwd);
		dao.create(user);
	}
	public void update(String mail) {
		User user = dao.findByEmail(mail);
		user.setActive(1);
		user.setEnable(true);
		dao.update(user);
	}
	public User findByNameAndPwd(String name, String pwd) {
		
		return dao.findByNameAndPwd(name,pwd);
	}
	public void changePic(User user, String path, String x, String x2,
			String y, String y2) {
		try {
			File file = new File("C:/upload",path);
			ImageLoader.fromFile(file).crop(Math.round(Float.parseFloat(x)), Math.round(Float.parseFloat(y)), Math.round(Float.parseFloat(x2)), Math.round(Float.parseFloat(y2))).writeToFile(file);
			user.setPic(path);
			
			dao.update(user);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
}
